<link rel="stylesheet" href="<?php echo $this->basePath('css/bootstrap/css/bootstrap.min.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('css/font-awesome/css/font-awesome.min.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('css/Ionicons/css/ionicons.min.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('js/plugins/iCheck/all.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('js/plugins/select2/css/select2.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('css/admin/css/AdminLTE.css'); ?>">

<link rel="stylesheet" href="<?php echo $this->basePath('css/admin/css/skins/_all-skins.min.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('css/admin/css/stylesheet.css'); ?>?t=<?php echo time(); ?>">

<!--[if lt IE 9]>
    <script type="text/javascript" src="<?php echo $this->basePath('js/html5shiv.min.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo $this->basePath('js/respond.min.js'); ?>"></script>
    <![endif]-->

<script type="text/javascript" src="<?php echo $this->basePath('js/jquery.min.js'); ?>"></script>
<!-- Bootstrap 3.3.7 -->
<script type="text/javascript" src="<?php echo $this->basePath('css/bootstrap/js/bootstrap.min.js'); ?>"></script>
<!-- iCheck -->
<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/iCheck/icheck.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo $this->basePath('js/adminlte.js'); ?>"></script>

<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/jquery-validation/jquery.validate.js'); ?>"></script>
<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/jquery-validation/additional-methods.js'); ?>" ></script>

<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/layer/layer.js'); ?>" ></script>
<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/laydate/laydate.js'); ?>" ></script>

<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/echarts/echarts.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/echarts/theme/shine.js'); ?>"></script>

<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/select2/js/select2.full.min.js'); ?>"></script>

<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/jquery-number/jquery.number.min.js'); ?>"></script>

<script type="text/javascript" src="<?php echo $this->basePath('js/headCommon.js'); ?>?t=<?php echo time(); ?>"></script>
<style>
    .content {
        margin-top: 0;
    }

    .content-wrapper {
        margin-left: 0;
        background: #ffffff;
    }
</style>

<?php
$form = $this->form;
$form->prepare();

echo $this->form()->openTag($form);
?>
<div class="content-wrapper">
    <section class="content-header">
        <h1 class="pull-right" id="dbshop-menu-top">
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存商品价格'); ?></button>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><?php echo $this->translate('商品名称'); ?></label>
                        <div class="col-sm-6">
                            <p class="form-control-static"><?php echo $this->escapeHtml($this->goodsInfo->getGoodsName()); ?></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><?php echo $this->translate('商品价格'); ?><span class="must_add_value">*</span></label>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                <?php echo $this->formElement($form->get('goodsPrice')); ?>
                            </div>
                            <?php echo $this->formElementErrors($form->get('goodsPrice'), ['class'=>'error-message']); ?>
                        </div>
                    </div>

                    <?php if (!$this->inSpecGoods) { ?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('商品会员价格'); ?><p class="text-sm text-blue" style="font-weight: normal;"><?php echo $this->translate('价格大于0 生效'); ?></p></label>
                            <div class="col-sm-5">
                                <table class="table shop-table table-bordered" style="margin-bottom:0px;">
                                    <tbody>
                                    <?php
                                    if(isset($this->goodsInfo)) $goodsUserGroupPriceArray = unserialize($this->goodsInfo->getGoodsUserGroupPrice());
                                    foreach ($this->userGroup as $ugValue) { ?>
                                        <tr>
                                            <td width="35%" style="padding: 0px;">&nbsp;<?php echo $this->escapeHtml($ugValue->getUserGroupName()); ?></td>
                                            <td style="padding: 0px;">
                                                <div class="input-group">
                                                    <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                                    <input type="text" min="0" name="goodsUserGroupPrice[<?php echo $ugValue->getUserGroupId(); ?>]" class="form-control" value="<?php echo isset($goodsUserGroupPriceArray[$ugValue->getUserGroupId()]) ? $goodsUserGroupPriceArray[$ugValue->getUserGroupId()] : 0; ?>">
                                                </div>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    <?php } ?>

                    <?php if($this->inSpecGoods) { ?>
                    <hr>
                        <table class="table shop-table table-bordered">
                            <thead>
                            <tr class="shop-bg-thead">
                                <th width="30%"><?php echo $this->translate('规格'); ?></th>
                                <th width="35%"><?php echo $this->translate('价格'); ?></th>
                                <th width="35%"><?php echo $this->translate('会员价'); ?></th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach ($this->inSpecGoods as $sgKey => $sgValue) {
                                $specTagStr = '';
                                $specTagIdArray = explode('-', $sgValue->getSpecTagId());
                                foreach ($specTagIdArray as $sTagId) {
                                    if (isset($this->goodsTagArray[$sTagId])) $specTagStr .= $this->goodsTagArray[$sTagId] . '|';
                                }
                                ?>
                                <tr>
                                    <td>
                                        <input type="hidden" name="specTagIdStr[]" value="<?php echo $sgValue->getSpecTagId(); ?>"><?php echo rtrim($specTagStr, '|'); ?>
                                    </td>
                                    <td>
                                        <div class="input-group">
                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                            <input type="text" name="specGoodsPrice[]" id="specGoodsPrice<?php echo $sgValue->getSpecTagId(); ?>" value="<?php echo $sgValue->getSpecGoodsPrice(); ?>" class="form-control input-sm">
                                        </div>
                                    </td>
                                    <td>
                                        <table class="table shop-table table-bordered" style="margin-bottom:0px;">
                                            <tbody>
                                            <?php $specGoodsUserGroupPriceArray = unserialize($sgValue->getSpecGoodsUserGroupPrice()); foreach ($this->userGroup as $ugValue) { ?>
                                                <tr>
                                                    <td width="35%" style="padding: 0px;">&nbsp;<?php echo $this->escapeHtml($ugValue->getUserGroupName()); ?></td>
                                                    <td style="padding: 0px;">
                                                        <div class="input-group">
                                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                                            <input type="text" name="specGoodsUserGroupPrice[<?php echo $sgValue->getSpecTagId(); ?>][<?php echo $ugValue->getUserGroupId(); ?>]" id="specGoodsUserGroupPrice-<?php echo $sgValue->getSpecTagId(); ?>-<?php echo $ugValue->getUserGroupId(); ?>" class="form-control input-sm" value="<?php echo isset($specGoodsUserGroupPriceArray[$ugValue->getUserGroupId()]) ? $specGoodsUserGroupPriceArray[$ugValue->getUserGroupId()] : 0; ?>">
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    <?php } ?>
                </div>

            </div>
        </div>
    </section>
</div>
<?php echo $this->form()->closeTag(); ?>

<script type="text/javascript">
    <?php if($this->status) echo "layer.load(2, {shade: [0.05, '#000'] });parent.location.reload();"; ?>

    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                goodsPrice: {
                    required: true,
                    number: true,
                    min: 0
                }
            },
            messages: {
                goodsPrice: {
                    required: "<?php echo $this->translate('商品价格不能为空!'); ?>",
                    number: "<?php echo $this->translate('商品价格必须为数字!'); ?>",
                    min: "<?php echo $this->translate('商品价格不能小于0!'); ?>"
                }
            }
        });
    });

    function goodsFormSubmit() {
        if($("input[name='specGoodsPrice[]']").length > 0) {
            let specGoodsStatus = true;
            $("input[name='specGoodsPrice[]']").each(function() {
                if(isNaN(this.value) || this.value <= 0) {
                    shopMessage('<?php echo $this->translate('规格商品价格要大于0!'); ?>');
                    $('#'+this.id).focus();
                    specGoodsStatus = false;
                    return false;
                }
            });
            if(!specGoodsStatus) return false;
        }

        return true;
    }
</script>

<script type="text/javascript" src="<?php echo $this->basePath('js/common.js'); ?>?t=<?php echo time(); ?>"></script>